package applet;

import lmf.*;
import processing.core.PApplet;
import processing.core.PImage;

public class ReleaseButton extends FilterButton {

	public Release release;
	GuiElement releaseInfoTag;
	
	public ReleaseButton()
	{
		releaseInfoTag = new GuiElement();
		//trackInfoTag.x = x-100;
		//trackInfoTag.y = y + 10;
	}
	
	
	@Override
	public void draw()
	{
		int cx = x;
		int cy = y;
		
		

		if(mouseOver()) //draw the menu of sub-categories
		{
			
			if(!active)
				if(GLOBAL.processing.mousePressed)
				{
					GLOBAL.processing.fill(GLOBAL.colorButtonActive, 0);
					GLOBAL.gu.drawBox(x, y, width, height, 0, GLOBAL.processing.color(150, 150, 200), 255);
					GLOBAL.gu.drawBox(x, y, width, height, 1, GLOBAL.processing.color(150, 150, 200), 255);
					cx += 1;
					cy += 1;
				}
				else
				{
					GLOBAL.processing.fill(GLOBAL.colorButtonBackground, alphaVal);//0 totally transparent, 255 totally oblique
					GLOBAL.processing.rectMode(PApplet.CORNER);
					GLOBAL.processing.rect(x, y, width, height);
					GLOBAL.gu.drawBox(x, y, width, height, 0, GLOBAL.processing.color(170, 150, 200), (int)alphaVal);
					GLOBAL.gu.drawBox(x, y, width, height, 1, GLOBAL.processing.color(170, 150, 200), (int)alphaVal);
				}
			else
			{
				if(GLOBAL.processing.mousePressed)
				{
					cx+=1;
					cy+=1;
					GLOBAL.processing.fill(GLOBAL.colorButtonActive,0);
				}
				else
				{
					GLOBAL.processing.fill(GLOBAL.colorButtonActive,alphaVal);
					GLOBAL.processing.rectMode(PApplet.CORNER);
					GLOBAL.processing.rect(x, y, width, height);
				}
				GLOBAL.gu.drawBox(x, y, width, height, 0, GLOBAL.processing.color(255, 0, 0), (int)alphaVal);
				GLOBAL.gu.drawBox(x, y, width, height, 1, GLOBAL.processing.color(255, 0, 0), (int)alphaVal);
			}
				
		}
		else //not mouseOver
		{
			if(active)
			{
				GLOBAL.processing.noStroke();
				GLOBAL.processing.fill(GLOBAL.colorButtonActive, alphaVal);
				GLOBAL.processing.rect(x, y, width, height);
				GLOBAL.gu.drawBox(x, y, width, height, 0, GLOBAL.processing.color(150, 150, 200), (int)alphaVal); //frame of the button
				GLOBAL.gu.drawBox(x, y, width, height, 1, GLOBAL.processing.color(150, 150, 200), (int)alphaVal);
			}
			else
			{
				GLOBAL.processing.rectMode(PApplet.CORNER);

		    	GLOBAL.processing.noStroke();
		    	GLOBAL.processing.fill(GLOBAL.colorButtonBackground/*backColor*/,alphaVal);
		    	GLOBAL.processing.rect(x, y, width, height);
		    	
		    	GLOBAL.gu.drawBox(x, y, width, height, 0, GLOBAL.processing.color(255, 255, 255), (int)alphaVal);
		    	GLOBAL.gu.drawBox(x, y, width, height, 1, GLOBAL.processing.color(0, 0, 0), (int)alphaVal);
			}
		}
			
		if(label != null)
		{
			//GLOBAL.processing.textAlign(GLOBAL.processing.LEFT);
			GLOBAL.processing.strokeWeight(2);
			GLOBAL.processing.fill(GLOBAL.colorButtonLabel,alphaVal);
			GLOBAL.processing.textAlign(PApplet.CENTER, PApplet.CENTER);
			GLOBAL.processing.textFont(GLOBAL.tFont,fontSize);
			if(icon!=null)
				GLOBAL.processing.text(label, cx + (width/2) + 10, cy + (height/2));
			else
			{
				if(height == 38) //ageButtons
				{
					GLOBAL.processing.textFont(GLOBAL.tFont32);
					GLOBAL.processing.text(label, cx + (width/2), cy + (height/2));
				}
				else
				{
					GLOBAL.processing.textFont(GLOBAL.tFont,fontSize);
					GLOBAL.processing.text(label, cx + (width/2), cy + (height/2));
				}
			}
				
		}

		if(icon != null)
		{
			GLOBAL.processing.imageMode(PApplet.CENTER);
			GLOBAL.processing.tint(255,alphaVal);
			if(width == 18)
				GLOBAL.processing.image(icon, x+width/2, y+height/2, 14+(cx-x),14+(cy-y));
			else if(width == 190) //sexButton
				GLOBAL.processing.image(icon, x+width/2, y+height/2, 0.8f*(width-(cx-x)-5),0.8f*(width-(cy-y)-5));
			else
				GLOBAL.processing.image(icon, x+5, y+5, 16,16);
			
		}

	}
	
	public void drawTag()
	{
	//if(active)
			//{
				
		//TODO: draw Track Lists using query info
		// key:
		//release.id -> ArrayList<Track> -> ArrayList<FilterButton> trackButtons -> TrackList
		
		//draw release info
		releaseInfoTag.x = 250;//this.x-120;
		releaseInfoTag.y = 520;//this.y;
		releaseInfoTag.width = releaseInfoTag.height = this.height*10;
		releaseInfoTag.width += 100;
		releaseInfoTag.height +=15;
		releaseInfoTag.draw();
		GLOBAL.processing.fill(200);
		GLOBAL.processing.text(this.release.title,releaseInfoTag.x+100, releaseInfoTag.y+30);
		//GLOBAL.processing.text(this.release.country, releaseInfoTag.x+50, releaseInfoTag.y+50);
		//GLOBAL.processing.text(this.release.language, releaseInfoTag.x+50, releaseInfoTag.y+70);
		//GLOBAL.processing.text(this.release.script, releaseInfoTag.x+50, releaseInfoTag.y+90);
			//}
		
		//AlbumLFM a = GLOBAL.http.getAlbumInfoLFM(GLOBAL.curRelease.mbid);
		//if(a!=null)
		//{
		//	PImage b = GLOBAL.processing.loadImage(a.image_medium);
		
		//	GLOBAL.processing.image(b, (float)releaseInfoTag.x+20, (float)releaseInfoTag.y+40);
		//}
	}
}
